<?php
require '../../../../framework/bootstrap.inc.php';
require '../../../../addons/hdz/function.php';

ini_set('display_errors', 'On');
error_reporting(E_ALL ^ E_NOTICE);
define('IN_MOBILE', true);
$input = file_get_contents('php://input');
if (!empty($input) && empty($_GET['out_trade_no'])) {
    $obj  = simplexml_load_string($input, 'SimpleXMLElement', LIBXML_NOCDATA);
    $data = json_decode(json_encode($obj), true);
    if (empty($data)) {
        exit('fail');
    }
    if ($data['result_code'] != 'SUCCESS' || $data['return_code'] != 'SUCCESS') {
        exit('fail');
    }
    
    $get = $data;

    $payment['code'] = $get['out_trade_no'];
    $payment = pdo_fetch("select * from " . tablename('hdz_paymentdetail') . ' where code=:code  limit 1', array(
        'code' => $payment['code'],
    ));
    if(!$payment)
    {
        exit('fail');
    }
    if($payment['tradestatus'] == 1)
    {
        exit('fail');
    }
    pdo_update('hdz_paymentdetail',array(
            'tradestatus' => 1,
            'response_time' => time()
        ),array(
            'id' => $payment['id'],
        )
    );//更新订单支付状态
    if($payment['transtype'] == 2 && $payment['refid'])
    {
        pdo_update('hdz_red',
            array('haspay' => 1),
            " id  in (".$payment['refid'].")"
        );
    }
    exit('success');
} else {
    $get = $_GET;
    exit('fail');
}
?>